<template>
	<view class="box">
		<view class="content">
			<view class="title">
				{{notice.title}}
			</view>
			<view class="publicher_a_startTime">
				<text>{{notice.nickname}}</text>
				<text>{{notice.createTime}}</text>
				<text v-if="userId == notice.publisherid" @click="edit">编辑</text>
				<text v-if="userId == notice.publisherid" @click="del">删除</text>
			</view>
			<view class="addressee">
				<text>收件人：</text>
				<text>{{notice.addressee}}</text>
			</view>
			<u-line color="#eee" margin="20rpx 0"/>
			<u-parse :html="notice.content"></u-parse>
			<!-- <rich-text :nodes="strHtml"></rich-text> -->
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: 0,
				userId: 0,
				notice: {}
			}
		},
		onLoad(option){ //option为object类型，会序列化上个页面传递的参数
			this.userId = uni.getStorageSync("userId")
			this.id = option.id
			this.getNoticeDetail()
		},
		methods: {
			async getNoticeDetail(){
				const res = await this.$myRequest({
					url: "/notice/info/" + this.id
				})
				this.notice = res.data.data
			},
			edit(){
				uni.navigateTo({
				    url: '/pages/sendNotice/sendNotice?id='+ this.id
				});
			},
			del(){
				uni.showModal({
					title: '提示',
					content: '是否确认删除?',
					success: res =>  {
						if (res.confirm) {
							this.$myRequest({
								url: '/notice/delete',
								data: [this.id],
								method: 'POST',
							}).then(res => {
								uni.showToast({
									icon: 'none',
									title: '删除成功'
								})
								setTimeout(() => {
									uni.reLaunch({
										url: '/pages/notice/notice'
									});
								}, 1500)
							})
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	
	.box{
		height: 100vh;
		background-color: #eee;
		margin-bottom: 200rpx;
		.content{
			background-color: #fff;
			padding: 20rpx;
			.title{
				font-size: 32rpx;
				line-height: 40rpx;
				margin: 20rpx 0;
			}
			.publicher_a_startTime{
				text:nth-child(1){
					color: $u-type-primary;
				}
				text:nth-child(2){
					margin-left: 15rpx;
					color: $u-tips-color;
				}
				text:nth-child(3),text:nth-child(4){
					margin-left: 15rpx;
					color: $u-type-primary;
				}
			}
			.addressee{
				margin-top: 20rpx;
				text:nth-child(2){
					color: $u-tips-color;
				}
			}
		}
	}
</style>
